
/*
    Copyright (C) 1999-2008 by Mark D. Hill and David A. Wood for the
    Wisconsin Multifacet Project.  Contact: gems@cs.wisc.edu
    http://www.cs.wisc.edu/gems/

    --------------------------------------------------------------------

    This file is part of the Ruby Multiprocessor Memory System Simulator, 
    a component of the Multifacet GEMS (General Execution-driven 
    Multiprocessor Simulator) software toolset originally developed at 
    the University of Wisconsin-Madison.

    Ruby was originally developed primarily by Milo Martin and Daniel
    Sorin with contributions from Ross Dickson, Carl Mauer, and Manoj
    Plakal.

    Substantial further development of Multifacet GEMS at the
    University of Wisconsin was performed by Alaa Alameldeen, Brad
    Beckmann, Jayaram Bobba, Ross Dickson, Dan Gibson, Pacia Harper,
    Derek Hower, Milo Martin, Michael Marty, Carl Mauer, Michelle Moravan,
    Kevin Moore, Andrew Phelps, Manoj Plakal, Daniel Sorin, Haris Volos, 
    Min Xu, and Luke Yen.
    --------------------------------------------------------------------

    If your use of this software contributes to a published paper, we
    request that you (1) cite our summary paper that appears on our
    website (http://www.cs.wisc.edu/gems/) and (2) e-mail a citation
    for your published paper to gems@cs.wisc.edu.

    If you redistribute derivatives of this software, we request that
    you notify us and either (1) ask people to register with us at our
    website (http://www.cs.wisc.edu/gems/) or (2) collect registration
    information and periodically send it to us.

    --------------------------------------------------------------------

    Multifacet GEMS is free software; you can redistribute it and/or
    modify it under the terms of version 2 of the GNU General Public
    License as published by the Free Software Foundation.

    Multifacet GEMS is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with the Multifacet GEMS; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307, USA

    The GNU General Public License is contained in the file LICENSE.

### END HEADER ###
*/

/*
 * $Id$
 *
 * Description: 
 *
 */

#ifndef StoreTrace_H
#define StoreTrace_H

#include "Global.h"
#include "RubyConfig.h"
#include "Address.h"
#include "Histogram.h"

class StoreTrace {
public:
  // Constructors
  StoreTrace() { }
  explicit StoreTrace(const Address& addr);

  // Destructor
  ~StoreTrace();
  
  // Public Methods
  void store(NodeID node);
  void downgrade(NodeID node);
  int getTotal() const { return m_total_samples; } 
  static void initSummary();
  static void printSummary(ostream& out);
  static void clearSummary();

  void print(ostream& out) const;
private:
  // Private Methods

  // Private copy constructor and assignment operator
  //  StoreTrace(const StoreTrace& obj);
  //  StoreTrace& operator=(const StoreTrace& obj);

  // Class Members (s_ prefix)
  static bool s_init;
  static int64 s_total_samples; // Total number of store lifetimes of all lines
  static Histogram* s_store_count_ptr;
  static Histogram* s_store_first_to_stolen_ptr;
  static Histogram* s_store_last_to_stolen_ptr;
  static Histogram* s_store_first_to_last_ptr;
  
  // Data Members (m_ prefix)

  Address m_addr;
  NodeID m_last_writer;
  Time m_first_store;
  Time m_last_store;
  int m_stores_this_interval;

  int64 m_total_samples; // Total number of store lifetimes of this line
  Histogram m_store_count;
  Histogram m_store_first_to_stolen;
  Histogram m_store_last_to_stolen;
  Histogram m_store_first_to_last;
};

bool node_less_then_eq(const StoreTrace* n1, const StoreTrace* n2);

// Output operator declaration
ostream& operator<<(ostream& out, const StoreTrace& obj);

// ******************* Definitions *******************

// Output operator definition
extern inline 
ostream& operator<<(ostream& out, const StoreTrace& obj)
{
  obj.print(out);
  out << flush;
  return out;
}

#endif //StoreTrace_H
